<template>
  <div id="app">
    <!-- 根据登录状态显示不同内容 -->
    <LoginView v-if="!isLoggedIn" @login-success="handleLoginSuccess" />
    <router-view v-else />
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import LoginView from './components/LoginView.vue'

const isLoggedIn = ref(false)
const router = useRouter()

// 检查登录状态
const checkLoginStatus = () => {
  const loggedIn = localStorage.getItem('isLoggedIn') || sessionStorage.getItem('isLoggedIn')
  isLoggedIn.value = loggedIn === 'true'
}

// 处理登录成功
const handleLoginSuccess = () => {
  isLoggedIn.value = true
  router.push('/')
}

// 组件挂载时检查登录状态
onMounted(() => {
  checkLoginStatus()
})
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  height: 100vh;
  overflow: hidden;
}
</style>
